package com.chenjj.bigdata.hive.util;

import com.chenjj.bigdata.hive.serde.CSVParser;
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;

public class CSVParserTester {


    private char separator=',';
    private char quotechar='\"';
    private char escape='\\';

    private CSVParser csvParser = new CSVParser(separator, quotechar, escape, CSVParser.DEFAULT_STRICT_QUOTES, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE);
    //正常的
    private String text1 = "\"a\",\"b\",123,\"c\",\"d\",123";
    //字段内有"的
    private String text2 = "1,\"c\"ccc\",\"d\",123";
    //字段内有,的
    private String text3 = "1,\"c,ccc\",\"d\",123";
    //字段内有换行符的
    private String text4 = "1,\"c\nccc\",\"d\",123";

    @Test
    public void testAll() throws IOException {
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text1)));
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text2)));
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text3)));
    }

    @Test
    public void test1() throws IOException {
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text1)));
    }

    @Test
    public void test2() throws IOException {
        String [] arr = csvParser.parseLineMulti(text2);
        System.out.println(Arrays.toString(arr));
    }

    @Test
    public void test3() throws IOException {
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text3)));
    }

    @Test
    public void test4() throws IOException {
        System.out.println(Arrays.toString(csvParser.parseLineMulti(text4)));
    }

}
